package de.hotmail.mapsmaps.LandsConstructor;

import java.io.File;

import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import org.bukkit.plugin.Plugin;

public class LandsConstructor extends JavaPlugin {

	@Override
	public void onEnable() {
		System.out.println("[LandsConstructor] Plugin load complete!");
		this.getCommand("setLands").setPermissionMessage(ChatColor.RED + "You dont have the permisson!");
		this.getCommand("setLands").setExecutor(new Port(this));
		loadConfig();
	}

	@Override
	public void onDisable() {
		System.out.println("[LandsConstructor] Plugin disabled!");
	}

	public FileConfiguration config;

	public void loadConfig() {
		config = getConfig();
		config.options().copyDefaults(true);

		if (new File("plugins/LandsConstructor/config.yml").exists()) {
			System.out.println("[LandsConstructor] config.yml load.");
		} else {
			saveDefaultConfig();
			System.out.println("[LandsConstructor] config.yml created an loaded.");
		}
	}

	public WorldGuardPlugin getWorldGuard()
    {
        Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
        if ((plugin == null) || (!(plugin instanceof WorldGuardPlugin)))
        {
            return null; //throws a NullPointerException, telling the Admin that WG is not loaded.
        }
        return (WorldGuardPlugin)plugin;
    }
}
